package org.tc.feign.platform;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tc.feign.service.FeignStoresService;
import org.tc.platform.entity.Stores;
import redis.clients.jedis.Jedis;

import java.util.List;

//@RequestMapping("/Stores")
@RestController
@CrossOrigin(origins = {"*"}, methods = {RequestMethod.GET, RequestMethod.POST}, allowCredentials = "true")
public class FeignStoresController {
    @Autowired
    private FeignStoresService feignStoresService;

    /**
     * 查询所有分店
     *
     * @return
     */
    @RequestMapping("/QueryAllStores")
    @ResponseBody
    public List<Stores> QueryAllStores() {
        List<Stores> list = feignStoresService.selectAll();
        return list;
    }

    @RequestMapping("/toRedisStoreId")
    public int storeId(Integer id){
        Jedis jedis=new Jedis("127.0.0.1",6379);
        System.out.println("分店id"+id);
        jedis.set("storeid",id.toString());
        return 1;
    }

    @RequestMapping("/delRedisStoreId")
    public int delStoreId(){
        Jedis jedis=new Jedis("127.0.0.1",6379);
        jedis.del("storeid");
        return 1;
    }

    @RequestMapping("/getRedisStoreId")
    public int getStoreId(){
        Jedis jedis=new Jedis("127.0.0.1",6379);
        int id=Integer.valueOf(jedis.get("storeid"));
        return id;
    }

    /**
     * 查询所有分店名称
     *
     * @return
     */
    @RequestMapping("/SelectName")
    @ResponseBody
    public List<Stores> SelectName() {
        List<Stores> list = feignStoresService.selectname();
        return list;
    }

    /**
     * 添加分店
     *
     * @param name   分店名称
     * @param region 分店地址
     * @return
     */
    @RequestMapping("/InsStores")
    @ResponseBody
    public int InsStores(String name, String region) {
        int count = feignStoresService.InsStores(name, region);
        return count;
    }

    /**
     * 删除分店
     *
     * @param id 分店ID
     * @return
     */
    @RequestMapping("/DelStores")
    @ResponseBody
    public int DelStores(Integer id) {
        int count = feignStoresService.deleteByPrimaryKey(id);
        return count;
    }

}
